importPackage(Packages.de.elo.ix.client);
//@include lib_Class.js
//@include lib_sol.common.Config.js
//@include lib_sol.common.SordUtils.js
//@include lib_sol.common.RepoUtils.js
//@include lib_sol.common.TranslateTerms.js
//@include lib_sol.common.ix.ServiceBase.js
//@include lib_sol.contact.Utils.js
var logger = sol.create("sol.Logger", { scope: "sol.contact.ix.services.Label" });
/**
* Retrieves available label types.
*
* # Configuration
*
* |Property|Description|
* |:------|:------|
* |||
*
* @author JHR, ELO Digital Office GmbH
* @version 1.0
*
* @eloix
* @requires sol.common.Config
* @requires sol.common.JsonUtils
* @requires sol.common.SordUtils
* @requires sol.common.RepoUtils
* @requires sol.common.TranslateTerms
* @requires sol.common.ix.RfUtils
* @requires sol.common.ix.ServiceBase
* @requires sol.contact.Utils
*/
sol.define("sol.contact.ix.services.GetLabelTypes", {
extend: "sol.common.ix.ServiceBase",
/**
* @cfg {Object} filter (optional) Additional filters which can be applied to the results
* @cfg {Boolean} filter.ignorePermissions (optional) If set, all available label types will be returned ignoring the user permissions (will only work in ELOix and ELOas)
*/
initialize: function (config) {
var me = this;
me.$super("sol.common.ix.ServiceBase", "initialize", [config]);
me.config = sol.contact.Utils.loadConfig();
},
/**
* Retrieves the data as spezified in the constructor configuration.
* @returns {String[]} Array with label types
*/
process: function () {
var me = this,
labelTemplates;
labelTemplates = me.getAllTemplates();
return me.convert(labelTemplates);
},
/**
* @private
* Retrieves all template Sord objects.
* @returns {de.elo.ix.client.Sord[]}
*/
getAllTemplates: function () {
var me = this,
conn = (me.filter && (me.filter.ignorePermissions === true) && ixConnectAdmin) ? ixConnectAdmin : ixConnect,
path = me.config.label.templateFolderId,
searchConf = {};
searchConf.includeFolders = false;
searchConf.includeDocuments = true;
searchConf.includeReferences = true;
searchConf.sordZ = SordC.mbAllIndex;
return sol.common.RepoUtils.findChildren(path, searchConf, conn);
},
/**
* @private
* Converts from Sords to Objects
* @param {de.elo.ix.client.Sord[]} reportTemplateSords
* @returns {Object[]}
*/
convert: function (reportTemplateSords) {
var converted = [];
if (reportTemplateSords) {
reportTemplateSords.forEach(function (sord) {
converted.push({
objId: sord.id,
name: sord.name,
desc: sord.desc
});
});
}
return converted;
}
});
/**
* Checks the preconditions for creation of a label.
*
* This service uses the mask of the parent to determine if it is a valid location for the label.
*
* Returns an Object:
*
* {
* valid: true,
* msg: "optional message"
* }
*
* # Configuration
*
* |Property|Description|
* |:------|:------|
* |fields.FILE_TYPE|The existence of this field on a mask, marks the element as a valid target|
*
* @author NM, ELO Digital Office GmbH
* @version 1.0
*
* @eloix
* @requires sol.common.Config
* @requires sol.common.JsonUtils
* @requires sol.common.SordUtils
* @requires sol.common.TranslateTerms
* @requires sol.common.ix.RfUtils
* @requires sol.common.ix.ServiceBase
*/
sol.define("sol.contact.ix.services.CheckLabelPreconditions", {
extend: "sol.common.ix.ServiceBase",
requiredConfig: ["ci", "targetId"],
/**
* @cfg {String} targetId (required)
* ObjectId of the target folder
*/
/**
* @cfg {de.elo.ix.client.ClientInfo} ci (required)
*/
initialize: function (config) {
var me = this;
me.$super("sol.common.ix.ServiceBase", "initialize", [config]);
me.config = sol.contact.Utils.loadConfig();
},
/**
* Checks the preconditions for creating a label.
* @returns {Object}
*/
process: function () {
var me = this,
result = { valid: false },
sord;
try {
sord = ixConnect.ix().checkoutSord(me.targetId, SordC.mbAllIndex, LockC.NO);
} catch (ex) {
me.logger.warn("invalid location for label", ex);
result.msg = sol.common.TranslateTerms.getTerm(me.ci, "sol.contact.ix.services.Label.errorNoElement");
return result;
}
if (me.isValidDocument(sord)) {
result.valid = true;
} else {
result.msg = sol.common.TranslateTerms.getTerm(me.ci, "sol.contact.ix.services.Label.errorInvalidLocation");
}
if (result.valid === true) {
result.types = sol.create("sol.contact.ix.services.GetLabelTypes", {}).process();
}
return result;
},
isValidDocument: function (sord) {
return sol.contact.Utils.isContact(sord);
}
});
/**
* @member sol.contact.ix.services.CheckLabelPreconditions
* @method RF_sol_contact_service_CheckLabelPreconditions
* @static
* @inheritdoc sol.common.ix.ServiceBase#RF_ServiceBaseName
*/
function RF_sol_contact_service_CheckLabelPreconditions(iXSEContext, args) {
logger.enter("RF_sol_contact_service_CheckLabelPreconditions", args);
var rfUtils = sol.common.ix.RfUtils,
config = rfUtils.parseAndCheckParams(iXSEContext, arguments.callee.name, args, "targetId"),
service, result;
config.ci = iXSEContext.ci;
service = sol.create("sol.contact.ix.services.CheckLabelPreconditions", config);
result = rfUtils.stringify(service.process());
logger.exit("RF_sol_contact_service_CheckLabelPreconditions", result);
return result;
}